
import 'package:dio/dio.dart' as dio;

import 'dart:io';
import 'dart:typed_data';
import 'package:chewie/chewie.dart';
import 'package:crypto/crypto.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:images_picker/images_picker.dart';
import 'package:multi_image_picker_view/multi_image_picker_view.dart';
import 'package:qianyi/controller/homeTabController.dart';
import 'package:qianyi/entity/home/tag_vo_list_entity.dart';
import 'package:qianyi/network/base_entity.dart';
import 'package:qianyi/network/http_entity.dart';
import 'package:qianyi/network/http_manager.dart';
import 'package:qianyi/state/token.dart';
import 'package:qianyi/utils/color_util.dart';
import 'package:qianyi/wcao/kit/index.dart';
import 'package:qianyi/wcao/ui/theme.dart';
import 'package:video_compress_plus/video_compress_plus.dart';
import 'package:video_thumbnail/video_thumbnail.dart';


import 'package:http/http.dart' as http;

import '../../../../network/http_config.dart';
import '../../../../ui/picker/custom/full_custom_example.dart';
import '../../../../utils/throttle.dart';

class AddAlbumViewMine extends StatefulWidget {
  const AddAlbumViewMine({Key? key}) : super(key: key);

  @override
  _addalbumViewState createState() => _addalbumViewState();
}
class _addalbumViewState extends State<AddAlbumViewMine> with AutomaticKeepAliveClientMixin<AddAlbumViewMine> ,SingleTickerProviderStateMixin{
  TextEditingController textEditingController = TextEditingController();
  HomeTabController homeTabController = Get.find();
  TokenController tokenController = Get.find();
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("创建专辑"),

      ),
      bottomNavigationBar: PreferredSize(
        preferredSize: Size.fromHeight(50.0), // 指定固定高度
        child: BottomAppBar(
        // color: Colors.blue,
        child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[

          MaterialButton(

            //背景颜色
            color: WcaoTheme.primaryOpacity,
            //边框样式
            shape: const RoundedRectangleBorder(
              //边框颜色
              side: BorderSide(
                color: Color(0xffe4e4e4),
                width: .5,
              ),
              //边框圆角
              borderRadius: BorderRadius.all(
                Radius.circular(8),
              ),
            ),
            //按钮高度
            height: 32,
            //按钮最小宽度
            minWidth: 60,
            //点击事件
            onPressed: () async {
              Iterable<ImageFile> list = homeTabController.imageController!.images;
              String value = textEditingController.text;
              if(value.trim().length<=0 || list.length<=0) {
                HudUtil.showFail("名称和图片不能为空");
                return;
              }
              HudUtil.show();
              ImageFile imageFile = list.first;
              File oriFile = new File(imageFile.path!);
// 2. compress file and get file.
              var result = await FlutterImageCompress.compressWithFile(
                  imageFile.path!, quality: 80);
              Digest fileMd5 = md5.convert(
                  oriFile.readAsBytesSync().sublist(1024, 5024));

              Map<String, dynamic> params1 = {
                'file': dio.MultipartFile.fromBytes(result!, filename: 'image_}.png'),
                'fileMd5': fileMd5.toString()
              };
              HttpEntity h8 = await HttpManager.getInstance().request(
                  url: '/util/fileoss/uploadOssVideoCover',
                  method: Method.file,
                  params: params1) as HttpEntity;
            Map<String,dynamic> params = {
              "name":value,
              "cover":h8.oriData['data'],
              "uid":tokenController.uid
            };
            HttpEntity h1 = await HttpManager.getInstance().request(url: '/platform/album/saveAlbum',params: params,method: Method.post) as HttpEntity;
            HudUtil.dismiss();
            Navigator.pop(context);
            },
            child:  Text(
              "点击发布",
              style: TextStyle(
                color: WcaoTheme.bgColor
              ),
            ),
          )
    // 其他按钮...
      ],
      ),
      ),
      ),
      body: Padding(
        padding: EdgeInsets.all(10),
        child: Column(
          children: [
            Title(color: Colors.white, child: Text("专辑名称",style: TextStyle(fontSize: 16),)),
            TextField(
              controller: textEditingController,
            ),
            // Title(color: WcaoTheme.indexBootBarColor, child: Text("请选择一张图片")),
            Container(
              height: 278,
              child: FullCustomExample(),
            )

          ],
        ),
      ),
    );
  }
  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => false;

}